<template>

  <!--

    对话框（2）：选择物料

    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectWork.title"
             :visible.sync="dialog_selectWork.visible"
             width="1100px">

    <!-- 检索条件 -->
    <el-form :model="dialog_selectWork.queryParams"
             :inline="true" v-show="dialog_selectWork.showSearch" label-width="68px">
      <el-input v-model="dialog_selectWork.queryParams.sysYesNoQc" v-show="false"/>
      <!-- 物料名称 -->
      <el-form-item label="单据编号" prop="docNum">
        <el-input
          v-model="dialog_selectWork.queryParams.docNum"
          placeholder="请输入单据编号"
          clearable
          size="small"
          @keyup.enter.native="getList_works"
        />
      </el-form-item>

      <!-- 物料编码 -->
      <el-form-item label="单据时间" prop="docDt">
        <el-input
          v-model="dialog_selectWork.queryParams.docDt"
          placeholder="请输入单据时间"
          clearable
          size="small"
          @keyup.enter.native="getList_works"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_works">搜索</el-button>
      </el-form-item>

    </el-form>


    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="dialog_selectWork.workList"
      row-key="itemUuid"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="派工时间" align="center" prop="docDt" width="150"/>
      <el-table-column label="加工号" align="center" prop="docNum" width="160"/>
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>

      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>

      <el-table-column label="工序内容" align="center" prop="processContent" width="120" />

      <el-table-column label="工序符号" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>

      <el-table-column label="设备类型" align="center" prop="wmsDictDeviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_device_type" :value="scope.row.wmsDictDeviceType"/>
        </template>
      </el-table-column>

      <el-table-column label="物料名称" align="center" prop="itemName" width="180px" :show-overflow-tooltip="true" />

      <el-table-column label="数量" align="center" prop="workQty" />

      <el-table-column label="计量单位" align="center" prop="wmsDictMeasuringUnit" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_measuring_unit" :value="scope.row.wmsDictMeasuringUnit"/>
        </template>
      </el-table-column>

      <el-table-column label="开始日期" align="center" prop="dtStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成日期" align="center" prop="dtDone" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtDone, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="派工号" align="center" prop="dispatchDocNum" width="160" />
      <el-table-column label="标准定额" align="center" prop="quotaWorkingHours" width="120" />

      <el-table-column label="经办人" align="center" prop="attentionUserName" width="150px"/>
      <el-table-column label="需质检" align="center" prop="sysYesNoQc">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoQc"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success" plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectWork_done(scope.row)"
          ><span> 选择</span></el-button>
        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="dialog_selectWork.total>0"
      :total="dialog_selectWork.total"
      :page.sync="dialog_selectWork.queryParams.pageNum"
      :limit.sync="dialog_selectWork.queryParams.pageSize"
      @pagination="getList_works"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectWork">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
  import { listWork } from "@/api/mes/work";
  export default {
  dicts: ['sys_normal_disable', 'mes_dict_process_type', 'mes_dict_process_name',
    'mes_dict_process_code','wms_dict_measuring_unit','sys_yes_no','wms_dict_device_type'],
  props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  },
  data() {
    return {
      sysYesNoQc:'',
      dialog_selectWork: {
        visible: false,
        showSearch: true,
        title: "请选择物料",
        total: 0,
        workList: [],
        queryParams:{
          itemName: null,
          sysYseNoQc: null,
        }
      },

      // 遮罩层
      loading: true,

      // 遮罩层
      visible: false,
      // 选中数组值
      userIds: [],
      // 总条数
      total: 0,
      // 未授权用户数据
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleId: undefined,
        userName: undefined,
        phonenumber: undefined
      },
      selectedUser: {
        id: null,
        nickName: null,
        userName: null
      }
    };
  },
  methods: {


    /** 读取列表：物料 */
    getList_works() {
      this.loading = true;
      this.dialog_selectWork.queryParams.sysYesNoQc = this.sysYesNoQc
      console.log(this.dialog_selectWork.queryParams)
      this.dialog_selectWork.queryParams.oaDictConfirmStatus='pass'
      listWork(this.dialog_selectWork.queryParams).then(response => {
        console.log( response )
        this.dialog_selectWork.workList = response.rows;
        this.dialog_selectWork.total = response.total;
        this.loading = false;
      });
    },



    // 完成：选择物料
    selectWork_done(user) {
      this.dialog_selectWork.visible = false;
      this.$emit("ok", user );
      console.log( user )
    },


    // 对话框：显示 - 选择物料
    dialog_show_selectWork() {
      this.getList_works()
      // this.form.selectedItem_tooltip = `请选择物料`
      this.dialog_selectWork.visible = true;
      this.dialog_selectWork.title = "选择物料";
    },

    // 对话框：隐藏 - 选择物料
    dialog_hide_selectWork() {
      this.dialog_selectWork.visible = false;
    },


    // 显示弹框
    show() {
      this.queryParams.roleId = this.roleId;
      this.getList();
      this.visible = true;
    },
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId);
    },
    // 查询表数据
    getList() {
      unallocatedUserList(this.queryParams).then(res => {
        this.userList = res.rows;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
